//
//  CardDetailView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2019/1/2.
//  Copyright © 2019年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CardDetailView: UIView {
    
    var model : CardDetailsModel! {
        didSet{
            
            updateData()
        }
    }
    
    let headView = CardDetailHeadView()
    let footView = CardDetailFootView()
    let freeButton = UIButton() //免费申请

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let redView = UIView()
        redView.backgroundColor = UIColor.red
        self.addSubview(redView)
        
        self.addSubview(headView)
        self.addSubview(footView)
        
        freeButton.backgroundColor = UIColor.red
        freeButton.setTitle(freeApplication, for: .normal)
        freeButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(freeButton)
        
        redView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 240))
        }
        
        headView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(redView)
        }
        
        footView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
        make.top.equalTo(headView.snp.bottom).offset(RATIO_H(maxNum: -40))
            make.height.equalTo(RATIO_H(maxNum: 250))
        }
        
        freeButton.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-StatusBarAddNavBarHeight)
            make.height.equalTo(RATIO_H(maxNum: 50))
        }
    }
    
    //MARK: 更新数据
    fileprivate func updateData() {
        
        footView.model = model
        headView.cardName = model.credit_name
        headView.percent = model.snum! + "%"
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
